
@extends('common.header')

<!-- 1.添加meta csrf_token -->
<meta name="csrf-token" content="{{ csrf_token() }}">  
<script src=" {{ asset('/js/jquery-1.8.3.min.js') }} "></script>
<script type="text/javascript">
	
	<!-- 2.设置全局ajax选项 -->
	$.ajaxSetup({
		headers: {
			'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
		}
	});
</script>
<body>

<br/>
<br/>
<br/>
<br/>

<!-- 页面标记  -->
<h3 style='margin-left:10%;color:#32CD32;font-size:25px;' >		
	{{ $title or '' }}
</h3>
	
<div class="col-xs-12 col-sm-6 col-md-11" style="margin-top:5%;margin-left:5%;margin-bottom:5%;" >
	<!-- 图片展示区域 -->
	@if( isset($pics_info) )
		@forelse ($pics_info as $pic)
		<div class="picShow" style='margin-left:3%;width:650px;height:auto;margin-bottom:20px;float:left;'  >
			<div style="float:left;margin-right:10px;">
				<img style='height:140px;margin-right:8%;border-radius:5px;' src="{{ $pic['pic_url'] }}" />
			</div>
			<!-- 图片 描述 -->
			<textarea name="desc" style='height:80px;width:320px;resize:none;float:left;margin-top:2%;' photoId="{{ $pic['id'] }}" class="form-control" >{{ $pic['desc'] or '' }}</textarea>
			
			<div style="width:200px;float:left;margin-top:1%;">
				<label for="face_{{ $pic['id'] }}" style="font-size:22px;cursor:pointer;" >
					@if( $pic['status']==1 )
						<input type='radio' name='face' id="face_{{ $pic['id'] }}" style="cursor:pointer;" value="{{ $pic['id'] }}" checked /> 
					<span style="font-size:15px;" >设为封面</span>
					@else
						<input type='radio' name='face' id="face_{{ $pic['id'] }}" style="cursor:pointer;" value="{{ $pic['id'] }}" /> 
					<span style="font-size:15px;" >设为封面</span>
					@endif
					
				</label>
			</div>
		</div>
		@empty
		@endforelse
	@else
	@endif
	
</div>
	
	
	
<div style="text-align:center;">
	<button  style="width:300px;" data-toggle="modal" data-target=".bs-example-modal-sm" class="btn btn-danger" >
		确认
	</button>
</div>

<div style="text-align:center;margin-top:1%;" >
	<a href="javascript:history.back();" style="width:300px;" class="btn btn-success">
		返回
	</a>
</div>


<div style="mairgin-bottom:80px;" id="photo" photoId="{{ $photo_id }}" >
</div>
	
<!-- 1.模态框 不要动 -->
<div class="modal fade bs-example-modal-sm" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel">
	<div class="modal-dialog modal-sm" role="document" id='show_info'  style="margin-top:80px;margin-left:45%;color:white;font-size:20px;">
	</div>
</div>
			

<script type="text/javascript">
		
	// 获取 token
	var _token = $('meta[name="csrf-token"]').attr('content');
	
	$(function(){
		
		// 执行 编辑 相册图片 描述信息
		$("button").click(function(){
			
			// 定义 描述 字符串
			var desc_str	= '';	
			$("textarea[name='desc']").each(function(){
				// 输入的 描述信息
				var val=$(this).val();
				// 相册ID
				var photoId=$(this).attr('photoId');
				// 按规则 拼接好
				desc_str += photoId+':'+val+',';
			});	
			
			// 封面信息
			var face = $("input[type='radio']:checked").val();
			
			// 相册ID
			var photo_id = $("#photo").attr('photoId');
			
			$.ajax({
				type:"post",
				url:"{{ url('/photos/updDesc') }}/"+photo_id,
				data:{desc:desc_str,face:face,_token:_token},
				async:true,    						
				dataType:"json",
				success:function(back){
					// 2.模态框 不要动
					$('#show_info').html( '' );
					$('#show_info').html( back['show_info'] );
					if( back['show_info']=='设置成功' )
					{
						setTimeout(function(){
							location.href="{{ url('/photos') }}";
						}, 1000);  
						
					}
					
				}
			});
			
			
		});
	});

</script>
</body>
@extends('common.footer')